package cn.stylefeng.guns.modular.weixin.utils;

import java.util.*;
import me.chanjar.weixin.mp.api.*;
import org.apache.commons.lang3.*;
import me.chanjar.weixin.mp.config.*;
import cn.hutool.http.*;
import java.util.concurrent.*;

public class WxUtils
{
    public static final String MP_TPL_CASE_CHANGE = "xqCHUG6bf-ED_9nbt9RmSnMRfExhbfuBIml2SgwV8YA";
    public static final String MP_TPL_API_ERROR = "2fbIUpyMiGD4AY2v6uCMEw177deZk5FamX_L6_POU9U";
    public static final String MP_TPL_PAY_APPLY = "x2BZ3canHIUfXraUH-QTH4UIOg1fmhZCgsuwXbcqgng";
    public static final String MP_TPL_PAY_NOTICE = "SRs7xzNT56cqHTBLdszzSYUamRa2wRy7uThCkga";
    public static final String MP_DOMAIN = "http://cjzn.jycjhw.com/";
    public static final String MA_PAY_MSG = "tpuNNGvmtqWYrAZCeQtk9oXlQkvFPWt_bcBbb9Q8iEE";
    public static final Map<String, String> templateIdMap;
    public static final Map<String, String> wechatAppConfig;
    public static final Map<String, String> maConfig;
    
    public static void switchMp(final WxMpService wxMpService) {
        switchMp(wxMpService, "default");
    }
    
    public static void switchMp(final WxMpService wxMpService, String mpName) {
        final WxMpConfigStorage wxMpConfigStorage = wxMpService.getWxMpConfigStorage();
        if (wxMpConfigStorage == null) {
            mpName = (String)StringUtils.defaultIfBlank((CharSequence)mpName, (CharSequence)"default");
            wxMpService.switchover((String)WxUtils.wechatAppConfig.get(mpName));
        }
    }
    
    public static String getMpCode(final String mpAccount) {
        final String appId = WxUtils.wechatAppConfig.get(mpAccount);
        return WxUtils.wechatAppConfig.get(appId);
    }
    
    public static String getMpAccount(final String appName) {
        final String appId = WxUtils.wechatAppConfig.get(appName);
        return WxUtils.wechatAppConfig.get(appName + "," + appId);
    }
    
    public static String getTemplateId(final String mpName, final String templateName) {
        return null;
    }
    
    public static String getDefaultMa() {
        return WxUtils.maConfig.get("default");
    }
    
    public static String getMpAppId(final String key) {
        return WxUtils.wechatAppConfig.getOrDefault(key, "default");
    }
    
    public static String getDefaultMp() {
        return WxUtils.wechatAppConfig.get("default");
    }
    
    public static String fingerprint(final String accessToken, final String openid, final String jsonString, final String jsonSignature) {
        final HttpRequest post = HttpUtil.createPost("https://api.weixin.qq.com/cgi-bin/soter/verify_signature?access_token=" + accessToken);
        post.form("openid", openid);
        post.form("json_string", jsonString);
        post.form("json_signature", jsonSignature);
        final HttpResponse execute = post.execute();
        final String body = execute.body();
        System.out.println(body);
        return body;
    }
    
    static {
        templateIdMap = new ConcurrentHashMap<String, String>();
        wechatAppConfig = new ConcurrentHashMap<String, String>();
        maConfig = new ConcurrentHashMap<String, String>();
    }
}
